package com.lock.lockblog.controller;

import com.lock.lockblog.model.Admins;
import com.lock.lockblog.util.AppConst;

import java.util.Random;

import javax.servlet.http.HttpServletRequest;


public class BaseController {
	
	/**
	 * 后台登录
	 * @param request
	 * @return
	 */
	protected Admins getLoginUser(HttpServletRequest request){
		Admins admin = (Admins) request.getSession().getAttribute(AppConst.Session_Admin);
		return admin;
	}

	/**
	 * 用户登录
	 * @param request
	 * @return
	 */
	/*protected Userinfo getUserLogin(HttpServletRequest request){
		Userinfo menber = (Userinfo) request.getSession().getAttribute(AppConst.Session_Member);
		return menber;
	}*/
	
	
	//用来产生随机验证码的
	private static Random rand = new Random();
	private static String[] str = {"0","1","2","3","4","5","6","7","8","9"};
		
	/**
	 * 返回6位随机数  Lock-玄清
	 * @return
	 */
	protected String getRandom(){
		//存放产生的随机数
    	String sms="";
    	//生成六位数的随机数
    	StringBuffer buf = new StringBuffer();
		for(int i=0;i<6;i++){
			buf.append(str[rand.nextInt(10)]);
		}
		sms= buf.toString();
		System.err.println(sms);
		return sms;
	}
	
	/**
	 * 返回4位随机数  Lock-玄清
	 * @return
	 */
	protected String getRandomone(){
		//存放产生的随机数
    	String sms="";
    	//生成六位数的随机数
    	StringBuffer buf = new StringBuffer();
		for(int i=0;i<4;i++){
			buf.append(str[rand.nextInt(10)]);
		}
		sms= buf.toString();
		System.err.println(sms);
		return sms;
	}
}
